package com.bky.mq.producer;

import com.alibaba.fastjson.JSONObject;
import com.bky.model.Add;
import com.bky.mq.base.BaseProducer;
import com.bky.mq.constant.Constants;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class AddProducer extends BaseProducer<Add>{
    @Value("${kafka.topic.name}")
    private String sendAddSubject;

    @Override
    protected String getMessage(Add message) {
        JSONObject result = new JSONObject();
        result.put(Constants.ADD_ID_KEY, message.getId());
        result.put(Constants.ADD_NAME_KEY, message.getTname());
        result.put(Constants.ADD_PWD_KEY, message.getTpwd());
        return result.toString();
    }

    @Override
    protected String buildMessageSubject() {
        return this.sendAddSubject;
    }

    @Override
    protected String getExceptionMessage() {
        return "AddProducer send fail";
    }

    @Override
    protected String getBusinessId(Add message) {
        return String.valueOf(message.hashCode());
    }
}
